# 506export_my_package/CMakeLists.txt
cmake_minimum_required(VERSION 3.22)

project(export_my_package)
# cmake -S . -B build -DCMAKE_INSTALL_PREFIX=/home/xcj/xcpp
file(WRITE include/slib.h "void SLib();")
file(WRITE slib.cpp [=[
#include <iostream>
#include "slib.h"
void SLib()
{
    std::cout<<"In SLib function!\n";
}
]=])
add_library(slib STATIC slib.cpp)

#需要导出头文件
set_target_properties(slib PROPERTIES PUBLIC_HEADER include/slib.h)

#[[
Target "slib" INTERFACE_INCLUDE_DIRECTORIES property contains path:
    "/home/xcj/code/src/506export_my_package/include"
  which is prefixed in the source directory.

]]
#target_include_directories(slib PUBLIC include)
# 路径被两次引用 1 编译slib库时 2 install export写入config时
target_include_directories(slib PUBLIC 
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> #install时为空,只有编译时有值
$<INSTALL_INTERFACE:include>  #只有install时有值 /home/xcj/xcpp/include
)

# -- Installing: /home/xcj/xcpp/lib/libslib.a
install(TARGETS slib 
EXPORT slib
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
PUBLIC_HEADER DESTINATION include
)

# <PackageName>Config.cmake
# slibConfig.cmake  写入库路径 头文件路径
# /home/xcj/xcpp/lib/config
install(EXPORT slib FILE slibConfig.cmake DESTINATION config)



